package ru.hh.team02.chat.messaging;

import java.util.HashMap;

import ru.hh.team02.chat.client.Client;

public class SendingService {
    private static final int WORKING_THREADS = 1; 
    
    private HashMap<String, SendingQueue> queues = 
            new HashMap<String, SendingQueue>();
    
    public SendingService(String[] roomNames) {
        for (String name : roomNames) {
            queues.put(name, new SendingQueue(WORKING_THREADS));
        }
    }

    /**
     * Put the message for sending in the queue.
     * The addressee is already encapsulated inside the message.
     * @param message
     */
//    public static void sendMessage(Message message) {
//        sendingQueue.add(message);
//    }

    /**
     * Create a message to a particular recipient and put it into the sending queue.
     * @param text Message text
     * @param recepient Recipient the message is addressed to.
     */
//    public static void sendMessage(String text, Client recepient) {
//        Message message = new Message(text, recepient);
//        sendMessage(message);
//    }

    /**
     * Create a bunch of messages to all the clients of the room and
     * put the messages in the queue for sending to them.
     * This method is just for optimization, as we may here once block the queue and
     * add all the messages instead of blocking and unblocking the queue for each message.
     * @param text Message text
     * @param room Room to send the message to
     */
    public void sendMessageToRoom(String text, String room) {
        queues.get(room).add(text, room);
    }
}
